﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ITXHWEB.Controllers
{
    public partial class ABFOLGEController
    {
        [ChildActionOnly]
        public ActionResult SABPGBN(string returnUrl)
        {
            ModelState.Clear();
            ViewBag.ReturnUrl = returnUrl;
            if (!MABF.IsABPReady)
            {
                INFO = "请扫描有效的单号";
            }
            return PartialView(MABF);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult SABPGBN(ABFOLGEModel model, string returnUrl)
        {
            try
            {
                ModelState.Clear();   
                dwData = VHP.VWBB.TBMain.NewRow();
                dwData["WBBMANDANT"] = app.Mandant;
                dwData["WBBGEBNR"] = model.ABPAUF.PadRight(8).Substring(0, 8);
                SResult = VHP.VWBB.QABPGEBNR(dwData);
                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    ABPOSModel abp = new ABPOSModel();
                    abp.ABPAUF = row["WBBAUFKRS"].ToString() + row["WBBAUFLFD"].ToString() + row["WBBAUFPOS"].ToString();
                    abp.ART = row["ABPART"].ToString();
                    abp.VAR = row["ABPVAR"].ToString();
                    abp.DESS = row["ABPDESS"].ToString();
                    abp.COLORIT = row["ABPCOLORIT"].ToString();
                    abp.FARBE = row["ABPFARBE"].ToString();
                    abp.BESCHICH = row["ABPBESCHICH"].ToString();
                    abp.WAKZ = row["ABPWAKZ"].ToString();
                    abp.AUFART = row["ABPAUFART"].ToString(); 
                    abp.PLANQTY =0.01*double.Parse( row["ABPSOLLMENGE1"].ToString());
                    MABF.ABPS.Add(abp);
                    model.ABPAUF = abp.ABPAUF;
                    MABF.ABPAUF = abp.ABPAUF;
                    MABF.MKFTP = row["TP"].ToString().Substring(11, 4);
                    ABFLOAD(model);

                    INFO = "单号扫描正确";
                }
               
            }
            catch (Exception ex)
            {
                INFO = ex.Message;
                Tracer.Error(ex.StackTrace, ex);
            }
            return RedirectToAction(MAPP, MAPP); 
        } 
    }
}
